package com.ironmaking.Controller;

import com.ironmaking.Entity.IngotRateTable;
import com.ironmaking.Handler.Security.Security;
import com.ironmaking.Service.impl.IngotRateService;
import com.ironmaking.Vo.params.IngotTableParams.IngotTableDataParams;
import com.ironmaking.Vo.params.IngotTableParams.UploadingIngotTableParam;
import com.ironmaking.Vo.params.YieldTableParams.UploadingYieldTableParams;
import com.ironmaking.Vo.results.ActionResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(value = "/ingot", tags = "成锭率相关接口")
@RequestMapping("/ingot")
public class IngotRateController {

    @Autowired
    IngotRateService ingotRateService;

    @PostMapping("/getIngotTable")
    @ApiOperation(value = "获取成材率单表信息", httpMethod = "POST")
    @Security
    public ActionResult getYieldTable(@RequestHeader("Authorization") String token, @RequestBody IngotTableDataParams ingotTableDataParams){
        Object result = ingotRateService.getIngotTableByYid(ingotTableDataParams.getIid(), ingotTableDataParams.getPageParams().getPage(), ingotTableDataParams.getPageParams().getSize());
        if (result == null)
            return ActionResult.fail(401,"未找到对应数据");
        return ActionResult.success(result);
    }

    @PostMapping("/uploadingIngotTable")
    @ApiOperation(value = "上传成锭率表格", httpMethod = "POST")
    @Security
    public ActionResult uploadingIngotTable(@RequestHeader("Authorization") String token, @RequestBody UploadingIngotTableParam uploadingIngotTableParam){

        int result = ingotRateService.uploadingIngotTable(uploadingIngotTableParam.getUserId(),uploadingIngotTableParam.getTableName(),uploadingIngotTableParam.getIngotRateTable());
        if (result==-1 )
            return ActionResult.fail(401,"数据上传失败");
        return ActionResult.success(result);
    }
}
